home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr44 / _xygraf.zip / DEMO.CPP < prev    next >
C/C++ Source or Header  |  1995-02-28  |  11KB  |  326 lines

  1. /*
  2. This file include working DEMO example of KNOW-HOW.GRAPHICS usage.
  3. This example use some code (main() function for DOS, or WinMain for
  4. Windows) to call common demo() function, which perform drawing on screen
  5. (DOS) or on DC (Windows). Windows demo wait until user click mouse
  6. button. 
  7. */
  8.  
  9. #include "bgipaint.h"
  10.  
  11. ///////////////////// Common DOS/Windows part of the DEMO ///////////////////
  12. //////////// This example draws "bird" and calendar for 1995 (1996) /////////
  13. #include <stdlib.h>
  14. #include <string.h>
  15.  
  16. class Demo : public KH_Paint
  17.     {
  18.     public:
  19.         void demo();
  20.         void bird();
  21.         void dn(int, int);
  22.         void wing(int, int);
  23.         void pero(int, int, int);
  24.         void calendar(int left, int top, int year, bool visocose);
  25.         int mon(int x, int y, char* mon, int first_day, int num_of_days);
  26.     };
  27. ///////////////////
  28. void Demo::demo()
  29.     {
  30.     set_add_zoom(1,1);          // ZOOM for all picture
  31.  
  32.     setfillstyle(SOLID_FILL, WHITE);
  33.     set_fill(ON);
  34.     set_zoom(0.1, 0.05);           // ZOOM for the part of picture,
  35.                                    // before the next "zoom" call
  36.     rectangle(0, 0, 5000, 10000);  // Will be multiplyed to ZOOM factor
  37.  
  38.     set_scroll(800, 500);
  39.     bird();
  40.     set_scroll(0, 500);
  41.     set_zoom(0.35, 0.33);
  42.  
  43.     setcolor(BLACK);
  44.     load("trip.chr");
  45. // Parameters: left, top, year, 0 if not visocose (1980 was)
  46.     calendar(80, 120, 1995, 0);
  47.  
  48.     char s[] = { "  KNOW-HOW.GRAPHICS" };
  49.     load("lcom.chr");
  50.     set_scroll(0, 0);
  51.     set_zoom(1, 1);
  52.     setcolor(GREEN);
  53.     for(int i = 0; i < strlen(s); i++)
  54.         {
  55.         rotate(loc(250, 250), 180 - 180 / strlen(s) * i);
  56.         draw_char(480, 250, s[i], 0);
  57.         }
  58.     rotate(0,0,0);
  59.     }
  60. /////////////////
  61. void Demo::calendar(int l, int t, int year, bool v)
  62.     {
  63.     int day = 7;              // for 1995
  64.     if(year == 1996)          // add cone for other years or use some
  65.     day = 1;              // calculations
  66.     int x = l;
  67.     int y = t + 15;
  68.     for(int i = 1; i <= 3; i++)
  69.     {
  70.     outtextxy(x, y, "Mo");
  71.     y += 30;
  72.     outtextxy(x, y, "Tu");
  73.     y += 30;
  74.         outtextxy(x, y, "We");
  75.         y += 30;
  76.         outtextxy(x, y, "Th");
  77.         y += 30;
  78.         outtextxy(x, y, "Fr");
  79.         y += 30;
  80.         outtextxy(x, y, "Sa");
  81.         y += 30;
  82.         outtextxy(x, y, "Su");
  83.  
  84.         y += 100;
  85.         }
  86.     x = l + 100;
  87.     y = t - 30;
  88.     day = mon(x, y, "January", day, 31);
  89.     int dv = v == 0 ? 28 : 29;
  90.  
  91.     day = mon(x + 340, y, "February", day, dv);
  92.     day = mon(x + 680, y, "March", day, 31);
  93.     day = mon(x + 1020, y, "April", day, 30);
  94.     day = mon(x, y +280, "May", day, 31);
  95.     day = mon(x + 340, y + 280, "June", day, 30);
  96.     day = mon(x + 680, y + 280, "July", day, 31);
  97.     day = mon(x + 1020, y + 280, "August", day, 31);
  98.     day = mon(x, y + 560, "September", day, 30);
  99.     day = mon(x + 340, y + 560, "October", day, 31);
  100.     day = mon(x + 680, y + 560, "November", day, 30);
  101.     day = mon(x + 1020, y + 560, "December", day, 31);
  102.     }
  103. //////////////
  104. int Demo::mon(int x1, int y1, char* head, int start, int num)
  105.     {
  106.     set_fill(ON);
  107.     setfillstyle(SOLID_FILL, WHITE);
  108.     outtextxy(x1 + 60, y1, head);
  109.     int days = 1;
  110.     int ln = start;
  111.     y1 += 15;
  112.  
  113.     char s[10];
  114.     while(1)
  115.         {
  116.         if(days > num)
  117.             return ln;
  118.         if(ln > 7)
  119.             {
  120.             x1 += 50;
  121.             ln = 1;
  122.             continue;
  123.             }
  124.         outtextxy(x1, y1 + 30 * ln, itoa(days, s, 10));
  125.         days++;
  126.     ln++;
  127.         }
  128.     }
  129. ////////////////
  130. void Demo::bird()
  131.     {
  132.     set_zoom(0.1, 0.05);       // To the next "zoom" call
  133.     setlinestyle(1, SOLID_LINE);
  134.     setcolor(BLUE);
  135.     setfillstyle(SOLID_FILL, YELLOW);
  136.  
  137.     int dy = 30;
  138.     for(int i = 1; i <= 12; i++)
  139.         {
  140.         ellipse(1600, 800 + 2 * dy * i, 0, 360, dy * i, dy * i);
  141.         ellipse(1600, 2300 - 2 * dy * i, 0, 360, dy * i, dy * i);
  142.         }
  143.     dn(1800, 1800);
  144.     wing(1900, 1400);
  145.     set_mirror(1600);
  146.     dn(1800, 1800);
  147.     wing(1900, 1400);
  148.     set_mirror(0);
  149.  
  150.     rotate(loc(0, 0), 0);
  151.     ellipse(1600, 700, 0, 360, 360, 360);
  152.     for(i = 0; i <= 60; i++)
  153.     {
  154.         pero(1800, 700, 1);
  155.         rotate(loc(1600, 700), 6 * i);
  156.         }
  157.     rotate(loc(1600, 2000), -90);
  158.     pero(1600, 2000, 7);
  159.     rotate(loc(1600, 2000), -100);
  160.     pero(1600, 2000, 5);
  161.     rotate(loc(1600, 2000), -80);
  162.     pero(1600, 2000, 5);
  163.  
  164.     rotate(loc(0, 0), 0);
  165.  
  166.     ellipse(1700, 600, 0, 360, 60, 130);
  167.     ellipse(1500, 600, 0, 360, 60, 130);
  168.     ellipse(1700, 600, 0, 360, 60, 60);
  169.     ellipse(1500, 600, 0, 360, 60, 60);
  170.     ellipse(1600, 800, 0, 360, 20, 90);
  171.     }
  172. //////////////////
  173. void Demo::wing(int xwin, int ywin)
  174.     {
  175.     for(int i = 0; i <= 10; i++)
  176.         {
  177.         rotate(xwin, ywin, 20 * i - 120);
  178.         pero(xwin, ywin, i / 2);
  179.         }
  180.     set_zoom(0.1, 0.05);
  181.     }
  182. /////////////////
  183. void Demo::dn(int xdn, int ydn)
  184.     {
  185.     rotate(xdn + 40, ydn + 40, -180);
  186.     for(int i = 0; i <= 19; i++)
  187.         {
  188.     rotate(xdn + 40, ydn + 40, 20 * i);
  189.         pero(xdn, ydn, 1);
  190.         }
  191.     }
  192. /////////////////
  193. void Demo::pero(int x, int y, int sz)
  194.     {
  195.     int x1 = x + 40 * sz;
  196.     int x2 = x + 100 * sz;
  197.     int x3 = x + 230 * sz;
  198.     int x4 = x + 300 * sz;
  199.     int y1 = y - 20 * sz;
  200.     int y2 = y - 30 * sz;
  201.     int y3 = y + 20 * sz;
  202.     int y4 = y + 30 * sz;
  203.     int points[] = {  x1, y, x2, y1, x3, y2, x4, y, x3, y4, x2, y3, x1, y };
  204.     fillpoly(7, points);
  205.     line(x, y, x + 300, y);
  206.     }
  207. ////////////////////// End of common DOS / Windows part /////////////////////
  208. /*
  209. //////////////////////////////// BGI DOS Demo ///////////////////////////////
  210. #include <iostream.h>
  211. #include <conio.h>
  212. void main()
  213.     {
  214.     clrscr();
  215. cout << "            K N O W - H O W . G R A P H I C S  6.0\r\n";
  216. cout << "\r\n";
  217. cout << "Source codes of DOS / Windows graphics Tool Kit for Borland C++ 3.x\r\n";
  218. cout << "\r\n";
  219. cout << "    KNOW-HOW.GRAPHICS  incapsulates  calls to  functions  of concrete library\r\n";
  220. cout << "and provide common code for DOS/Windows graphics\r\n";
  221. cout << "Current  version  works  with  DOS  (BGI) and  Windows (GDI), but  only minor\r\n";
  222. cout << "changes are required  to add  interface to any  other  library which  support\r\n";
  223. cout << "standart drawing functions (moveTo, lineTo and so on)\r\n";
  224. cout << "This code also  support Zooming,  Scrolling, Rotation  and  Complex  (Nested)\r\n";
  225. cout << "Rotation  of image  or part  of it.  This  features  could  be used  for  the\r\n";
  226. cout << "development  of  CAD systems, Vector  drawing tools, and Writing of platform-\r\n";
  227. cout << "independent  functions. Size of  code  written with  KH.GRAPHICS is 2-5 times\r\n";
  228. cout << "smaller then without it.\r\n";
  229. cout << "BGI fonts ( including filled fonts ) could  be used  under DOS  and  Windows,\r\n";
  230. cout << "all  image   transformations,  including  rotations  are  valid  withs  them.\r\n";
  231. cout << "\r\n";
  232. cout << "Additional  development  tools  include  heap  check  modules  (DOS only) for\r\n";
  233. cout << "memory leaks detections even if program hung-up the system.\r\n";
  234. cout << "\r\n";
  235.     getch();
  236.     int gdriver = DETECT, gmode;
  237.     initgraph(&gdriver, &gmode, "");
  238.  
  239.     Demo* paint = new Demo();
  240.     paint->demo();
  241.  
  242.     delete paint;
  243.     getch();
  244.     closegraph();
  245. cout << "            K N O W - H O W . G R A P H I C S  6.0\r\n";
  246. cout << "\r\n";
  247. cout << "Additional products:\r\n";
  248. cout << "    KNOW-HOW.GRAF 6.0. Business and  Scientific diagrams.  Supported types of\r\n";
  249. cout << "grafs:  MARKER,  LINE, LINE-and-MARKER,   BAR,  BAR-3D, STACKED BAR (could be\r\n";
  250. cout << "expanded).  Manual   or   automatic   calculation  of  the  labels  position,\r\n";
  251. cout << "multiple datasets,  four  axes (two X  and  two  Y)  with  different  scales.\r\n";
  252. cout << "Product is  based  on the KNOW-HOW.GRAPHICS and have access to all its tools,\r\n";
  253. cout << "as Zooming,  Scrolling,  Rotation  and  other. Same code for DOS and Windows.\r\n";
  254. cout << "\r\n";
  255. cout << "    KNOW-HOW.SLANG 6.0. Basic-like language  with  access  to KH.GRAPHICS and\r\n";
  256. cout << "KH.GRAF functions. Could be  used  in  C++  program  to  acces  its  specific\r\n";
  257. cout << "functions as well. Multy file projects\r\n";
  258. cout << "Usage: Data  processing  tools, Data  presentations (load/calc/plot/drawing),\r\n";
  259. cout << "Vector  drawing  tools,  BGI  /  GDI  maketing tools (no compilation stage).\r\n";
  260. cout << "\r\n";
  261. cout << "         <<< All source codes available >>>\r\n";
  262. cout << "\r\n";
  263.     getch();
  264.     clrscr();
  265. cout << "\r\n";
  266. cout << "\r\n";
  267. cout << "Contacts: Stepan Vartanov, ad398@cfn.cs.dal.ca\r\n";
  268. cout << "To order send check or money to: \r\n";
  269. cout << "  P.O.Box 34041, Scotia Scuare RPO, Halifax, N.S., Canada, B3J 3S1\r\n";
  270. cout << "\r\n";
  271. cout << " 1. KNOW-HOW.GRAPHICS _____________________________________ 20 $ USA\r\n";
  272. cout << " 2. KNOW-HOW.GRAF  ( KH.GRAPHICS included ) _______________ 50 $ USA\r\n";
  273. cout << " 3. KNOW-HOW.SLANG ( KH.GRAPHICS and KH.GRAF included ) ___ 95 $ USA\r\n";
  274. cout << "\r\n";
  275. cout << "\r\n";
  276. cout << "\r\n";
  277.     getch();
  278.     }
  279. */
  280. ////////////////////////////// GDI Windows Demo /////////////////////////////
  281. // This example demonstrates output to OWL window. If necessary,
  282. // any other Windows library could be used.
  283. /*
  284. #include <owl.h>
  285.  
  286. class TMyApp : public TApplication
  287. {
  288. public:
  289.   TMyApp(LPSTR AName, HINSTANCE hInstance, HINSTANCE hPrevInstance,
  290.     LPSTR lpCmdLine, int nCmdShow)
  291.     : TApplication(AName, hInstance, hPrevInstance, lpCmdLine, nCmdShow) {};
  292.   virtual void InitMainWindow();
  293. };
  294.  
  295. _CLASSDEF(TMyWindow)
  296. class TMyWindow : public TWindow, public Demo
  297. {
  298. public:
  299.   TMyWindow(PTWindowsObject AParent, LPSTR ATitle)
  300.     : TWindow(AParent, ATitle), Demo() { DC = GetDC(HWindow); }
  301.   virtual void WMLButtonDown(RTMessage Msg)
  302.     = [WM_FIRST + WM_LBUTTONDOWN];
  303. };
  304.  
  305. void TMyWindow::WMLButtonDown(RTMessage)
  306.     {
  307.     DC = GetDC(HWindow);
  308.     demo();
  309.     ReleaseDC(HWindow, DC);
  310.     }
  311.  
  312. void TMyApp::InitMainWindow()
  313. {
  314.   MainWindow = new TMyWindow(NULL, Name);
  315. }
  316.  
  317. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  318.   LPSTR lpCmdLine, int nCmdShow)
  319. {
  320.   TMyApp MyApp("Sample KNOW-HOW.GRAPHICS Program", hInstance, hPrevInstance,
  321.                lpCmdLine, nCmdShow);
  322.   MyApp.Run();
  323.   return MyApp.Status;
  324. }
  325. */
  326.